Improve locale-aware manual links - #27
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review: PR #27 — Improve locale-aware manual linksOverviewThis PR improves the browser locale detection on the landing page by switching from the single Code Quality — Good
Potential Issues / Suggestions
SecurityNo concerns. The replacement is constrained to elements with class VerdictReady to merge. Clean, focused improvement with no regressions. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@index.html`:
- Around line 47-55: The current logic uses locales.some(...) which ignores the
browser's preferred-order; instead pick the first supported locale in priority
order and only switch when that primary locale is Japanese. Update the code
around navigatorLanguages/locales/prefersJapanese: define a supportedLocales set
(e.g. ['ja', 'en', ...] as appropriate), iterate locales in order to find
primaryLocale = locales.find(l =>
supportedLocales.has(l.slice(0,2).toLowerCase())) ?? locales[0], then set
prefersJapanese = primaryLocale.toLowerCase().startsWith('ja') and keep the
early return if false. This preserves navigator.languages priority and only
switches when the top-supported locale is Japanese.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| const navigatorLanguages = window.navigator.languages; | ||
| const locales = (navigatorLanguages && navigatorLanguages.length) | ||
| ? navigatorLanguages | ||
| : [window.navigator.language ?? '']; | ||
| const prefersJapanese = locales.some((locale) => locale.toLowerCase().startsWith('ja')); | ||
|
|
||
| if (!prefersJapanese) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Respect the browser’s locale priority order.
Using .some() switches to Japanese even for navigator.languages = ['en-US', 'ja-JP'], where English is the preferred supported locale. Consider choosing the first supported locale, then switching only when that locale is Japanese.
🌐 Proposed locale-priority fix
const locales = (navigatorLanguages && navigatorLanguages.length)
? navigatorLanguages
: [window.navigator.language ?? ''];
- const prefersJapanese = locales.some((locale) => locale.toLowerCase().startsWith('ja'));
+ const preferredSupportedLocale = locales
+ .map((locale) => locale.toLowerCase())
+ .find((locale) => locale.startsWith('ja') || locale.startsWith('en'));
+ const prefersJapanese = preferredSupportedLocale?.startsWith('ja') ?? false;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const navigatorLanguages = window.navigator.languages; | |
| const locales = (navigatorLanguages && navigatorLanguages.length) | |
| ? navigatorLanguages | |
| : [window.navigator.language ?? '']; | |
| const prefersJapanese = locales.some((locale) => locale.toLowerCase().startsWith('ja')); | |
| if (!prefersJapanese) { | |
| return; | |
| } | |
| const navigatorLanguages = window.navigator.languages; | |
| const locales = (navigatorLanguages && navigatorLanguages.length) | |
| ? navigatorLanguages | |
| : [window.navigator.language ?? '']; | |
| const preferredSupportedLocale = locales | |
| .map((locale) => locale.toLowerCase()) | |
| .find((locale) => locale.startsWith('ja') || locale.startsWith('en')); | |
| const prefersJapanese = preferredSupportedLocale?.startsWith('ja') ?? false; | |
| if (!prefersJapanese) { | |
| return; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@index.html` around lines 47 - 55, The current logic uses locales.some(...)
which ignores the browser's preferred-order; instead pick the first supported
locale in priority order and only switch when that primary locale is Japanese.
Update the code around navigatorLanguages/locales/prefersJapanese: define a
supportedLocales set (e.g. ['ja', 'en', ...] as appropriate), iterate locales in
order to find primaryLocale = locales.find(l =>
supportedLocales.has(l.slice(0,2).toLowerCase())) ?? locales[0], then set
prefersJapanese = primaryLocale.toLowerCase().startsWith('ja') and keep the
early return if false. This preserves navigator.languages priority and only
switches when the top-supported locale is Japanese.
What changed
Why
Notes
Summary by CodeRabbit